const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const listFinancialEventGroups = {};
listFinancialEventGroups.generateOption = function(seller_id, mws_auth_token, financialEventGroupStartedAfter, financialEventGroupStartedBefore=null, maxResultsPerPage=null){
  let baseOption = {
    'Version': '2015-05-01',
    'Action': 'ListFinancialEventGroups',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'FinancialEventGroupStartedAfter': financialEventGroupStartedAfter // new Date(2016, 11, 24)
  };
  if (financialEventGroupStartedBefore)
    baseOption['FinancialEventGroupStartedBefore'] = financialEventGroupStartedBefore;
  if (maxResultsPerPage)
    baseOption['MaxResultsPerPage'] = maxResultsPerPage;
  return baseOption;
};

listFinancialEventGroups._ = function(options) {
  if (!isProduction) {
    return amazonMws.finances.search(options);
  } else {
    console.error("bot not implemented!")
  }
};

listFinancialEventGroups.listFinancialEventGroups = function(seller_id, mws_auth_token, financialEventGroupStartedAfter, financialEventGroupStartedBefore=null, maxResultsPerPage=null) {
  return this._(this.generateOption(seller_id, mws_auth_token, financialEventGroupStartedAfter, financialEventGroupStartedBefore, maxResultsPerPage));
};

module.exports = listFinancialEventGroups;